package com.sayimo.maker.base.service.impl;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.sayimo.framework.common.util.StringUtil;
import com.sayimo.framework.exception.DaoException;
import com.sayimo.framework.exception.ServiceException;
import com.sayimo.maker.base.dao.AppManagerDao;
import com.sayimo.maker.base.service.AppManagerService;
import com.sayimo.maker.base.vo.AppManager;
import com.sayimo.maker.commons.Constant;



@Service(value = "appManagerService")
public class AppManagerServiceImpl implements AppManagerService{
	
	private  Logger logger=LogManager.getLogger(AppManagerServiceImpl.class.getName());
	
	@Resource(name = "appManagerDao")
	private AppManagerDao appManagerDao;
	
	@Override
	public Map<String, Object> getNewApp(Integer mobileSysType) throws ServiceException {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		Map<String, Object> temMap = new HashMap<String, Object>();
		try {
			AppManager appManager = appManagerDao.queryNewApp(mobileSysType);
			if(appManager != null){
				
				temMap.put("id", StringUtil.nullReplace(appManager.getId()));
				temMap.put("name", StringUtil.nullReplace(appManager.getName()));
				temMap.put("appSign", StringUtil.nullReplace(appManager.getAppSign()));
				temMap.put("iconUrl", StringUtil.nullReplace(appManager.getIconUrl()));
				temMap.put("version", StringUtil.nullReplace(appManager.getVersion()));
				temMap.put("detail", StringUtil.nullReplace(appManager.getDetail()));
				temMap.put("appName", StringUtil.nullReplace(appManager.getAppName()));
				temMap.put("networkType", StringUtil.nullReplace(appManager.getNetworkType()));
				temMap.put("networkUrl", StringUtil.nullReplace(appManager.getNetworkUrl()));
				temMap.put("localUrl", StringUtil.nullReplace(appManager.getLocalUrl()));
				temMap.put("networkUrl", StringUtil.nullReplace(appManager.getNetworkUrl()));	
				temMap.put("createUser", StringUtil.nullReplace(appManager.getCreateUser()));
				temMap.put("createDate", StringUtil.nullReplace(appManager.getCreateDate()));
				temMap.put("updateDate", StringUtil.nullReplace(appManager.getUpdateDate()));
				resultMap.put(Constant.STATUS, Constant.STATUS_SUCCESS);
				resultMap.put(Constant.DATA,temMap);
			}else{
				resultMap.put(Constant.STATUS, Constant.STATUS_ERROR);
				resultMap.put(Constant.ERROR_CODE, Constant.SYSTEM_NO_DATA);
			}
		} catch (DaoException e) {
			logger.error(e);
			throw new ServiceException(e);
		}
		return resultMap;
	}

}
